﻿using System;
using BrainTechLLC;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace BrainTechLLC.Silverlight.ClientApplication
{
    public partial class EditLocationInt : UserControl
    {
        public event EventHandler<ObjectEventArgs<LocationInt>> RequestGoLocation;
        public event EventHandler<ObjectEventArgs<LocationInt>> RequestEditGameLocation;

        public static readonly DependencyProperty GoButtonVisibleProperty = DependencyProperty.Register(
            "GoButtonVisible",
            typeof(bool),
            typeof(EditLocationInt),
            new PropertyMetadata(true, new PropertyChangedCallback(GoButtonVisibleChanged)));

        public bool GoButtonVisible
        {
            get { return (bool)GetValue(GoButtonVisibleProperty); }
            set { SetValue(GoButtonVisibleProperty, value); }
        }

        private static void GoButtonVisibleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            EditLocationInt t = (EditLocationInt)d;
            t.GoButtonVisible = (bool)e.NewValue;
            t.UpdateButtons();
        }

        public void UpdateButtons()
        {
            btnGoto.SetVisible(GoButtonVisible);
        }

        public static readonly DependencyProperty LocationIntProperty = DependencyProperty.Register(
            "LocationInt",
            typeof(LocationInt),
            typeof(EditLocationInt),
            new PropertyMetadata(null, new PropertyChangedCallback(LocationIntChanged)));

        public LocationInt LocationInt
        {
            get { return (LocationInt)GetValue(LocationIntProperty); }
            set { SetValue(LocationIntProperty, value); }
        }

        private static void LocationIntChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            EditLocationInt t = (EditLocationInt)d;
            t.LocationInt = (LocationInt)e.NewValue;
            t.txtID.Text = t.LocationInt.ToString();
        }

        public EditLocationInt()
        {
            // Required to initialize variables
            InitializeComponent();
        }

        private void btnGoto_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(txtID.Text))
                return;

            if (RequestGoLocation != null)
                RequestGoLocation(this, new ObjectEventArgs<LocationInt>(txtID.Text.ParseLocationInt()));
        }

        private void btnEdit_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(txtID.Text))
                return;

            if (RequestEditGameLocation != null)
                RequestEditGameLocation(this, new ObjectEventArgs<LocationInt>(txtID.Text.ParseLocationInt()));            
        }
    }
}